#!/usr/bin/env bash

base_dir="$(cd "$(dirname "$0")" && pwd -P)"
bin_dir=${base_dir}/bin
etc_dir=${base_dir}/etc
omnisharp_dir=${base_dir}/omnisharp

mono_cmd=${bin_dir}/mono
omnisharp_cmd=${omnisharp_dir}/OmniSharp.exe
config_file=${etc_dir}/config

chmod 755 "${mono_cmd}"

no_omnisharp=false

if [ "$1" = "--no-omnisharp" ]; then
    shift
    no_omnisharp=true
fi

export MONO_CFG_DIR=${etc_dir}
export MONO_ENV_OPTIONS="--assembly-loader=strict --config ${config_file}"

if [ "$no_omnisharp" = true ]; then
    "${mono_cmd}" "$@"
else
    "${mono_cmd}" "${omnisharp_cmd}" "$@"
fi
